var _Step = require('scenes/game/toturial/step.js');
var _inherit = require('core/inherit.js');
var _global = require('global/global.js');

function Step() {
    _Step.call(this);
    this.mShow1 = false;
    this.mShow2 = false;
    this.mMerged = false;
    this.mEmptyPool = false;
}
_inherit(Step, _Step);
Step.prototype.onAbsorbStart = function (accept) {
    if (accept) {
        if (!this.mPool.hasSlot()) {
            this.mEmptyPool = true;
        }
        if (!this.mMerged) {
            var merged = this.mCells.getMergeHis().getCurrent();
            if (merged.getMergeCount() > 0) {
                this.mMerged = true;
            }
        }
        if (this.mEmptyPool && this.mMerged) {
            this.mToturial.nextStep();

            this.mToturial = null;
            this.mLocal = null;
            this.mPool = null;
        }
    }
};
Step.prototype.onSlideinStart = function (cell) {
    if (cell == 1 && !this.mShow1) {
        this.mShow1 = true;
        var rtf = this.rtfHeader().textBuilder()
            .addText('1', 'green')
            .addText(' will ONLY add with ', 'black')
            .addText('2', 'red')
            .create();
        this.mToturial.showHeaderTip(rtf);
        this.mToturial.hideFooter();
    }
    if (cell == 2 && !this.mShow2) {
        this.mShow2 = true;
        var rtf = this.rtfHeader().textBuilder()
            .addText('2', 'red')
            .addText(' will ONLY add with ', 'black')
            .addText('1', 'green')
            .create();
        this.mToturial.showHeaderTip(rtf);
    }
};
Step.prototype.onStart = function (toturial, local) {
    this.mToturial = toturial;
    this.mLocal = local;

    this.mPool = this.mLocal.find('gamearea.slotpool');
    this.mPool.addSlots([1, 1, 1, 1, 2, 2, 2, 2], true);
    this.mCells = this.mLocal.find('gamearea.cells');
};

module.exports = Step;